package com.example.demo.role.controller;

import com.example.demo.role.entity.Role;
import com.example.demo.role.service.RoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.List;

@RestController
@Api(tags = "role")
@EnableSwagger2
public class RoleController {

    @Autowired
    private RoleService roleService;

    @ApiOperation(value = "添加用户")
    @PostMapping("/addRole")
    public int insertRole (Role role) {
        return roleService.addRole(role);
    }

    @ApiOperation(value = "删除角色")
    @PostMapping("/deleteRole")
    public int dropRole(int id) {
        return roleService.deleteRole(id);
    }

    @ApiOperation(value = "更新角色")
    @PostMapping("/updateRole")
    public int changeRole(Role role) {
        return roleService.updateRole(role);
    }

    @ApiOperation(value = "查询全部角色")
    @GetMapping("/selectAllRole")
    public List<Role> selectAll() {
        return roleService.selectAllRole();
    }
}
